/*     */ package com.cr.common.utils;
/*     */ 
/*     */ import com.cr.common.json.JSON;
/*     */ import java.io.PrintWriter;
/*     */ import java.io.StringWriter;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.shiro.SecurityUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ public class LogUtils {
/*  19 */   public static final Logger ERROR_LOG = LoggerFactory.getLogger("sys-error");
/*     */   
/*  20 */   public static final Logger ACCESS_LOG = LoggerFactory.getLogger("sys-access");
/*     */   
/*     */   public static void logAccess(HttpServletRequest request) throws Exception {
/*  30 */     String username = getUsername();
/*  31 */     String jsessionId = request.getRequestedSessionId();
/*  32 */     String ip = IpUtils.getIpAddr(request);
/*  33 */     String accept = request.getHeader("accept");
/*  34 */     String userAgent = request.getHeader("User-Agent");
/*  35 */     String url = request.getRequestURI();
/*  36 */     String params = getParams(request);
/*  38 */     StringBuilder s = new StringBuilder();
/*  39 */     s.append(getBlock(username));
/*  40 */     s.append(getBlock(jsessionId));
/*  41 */     s.append(getBlock(ip));
/*  42 */     s.append(getBlock(accept));
/*  43 */     s.append(getBlock(userAgent));
/*  44 */     s.append(getBlock(url));
/*  45 */     s.append(getBlock(params));
/*  46 */     s.append(getBlock(request.getHeader("Referer")));
/*  47 */     getAccessLog().info(s.toString());
/*     */   }
/*     */   
/*     */   public static void logError(String message, Throwable e) {
/*  58 */     String username = getUsername();
/*  59 */     StringBuilder s = new StringBuilder();
/*  60 */     s.append(getBlock("exception"));
/*  61 */     s.append(getBlock(username));
/*  62 */     s.append(getBlock(message));
/*  63 */     ERROR_LOG.error(s.toString(), e);
/*     */   }
/*     */   
/*     */   public static void logPageError(HttpServletRequest request) {
/*  73 */     String username = getUsername();
/*  75 */     Integer statusCode = (Integer)request.getAttribute("javax.servlet.error.status_code");
/*  76 */     String message = (String)request.getAttribute("javax.servlet.error.message");
/*  77 */     String uri = (String)request.getAttribute("javax.servlet.error.request_uri");
/*  78 */     Throwable t = (Throwable)request.getAttribute("javax.servlet.error.exception");
/*  80 */     if (statusCode == null)
/*  82 */       statusCode = Integer.valueOf(0); 
/*  85 */     StringBuilder s = new StringBuilder();
/*  86 */     s.append(getBlock((t == null) ? "page" : "exception"));
/*  87 */     s.append(getBlock(username));
/*  88 */     s.append(getBlock(statusCode));
/*  89 */     s.append(getBlock(message));
/*  90 */     s.append(getBlock(IpUtils.getIpAddr(request)));
/*  92 */     s.append(getBlock(uri));
/*  93 */     s.append(getBlock(request.getHeader("Referer")));
/*  94 */     StringWriter sw = new StringWriter();
/*  96 */     while (t != null) {
/*  98 */       t.printStackTrace(new PrintWriter(sw));
/*  99 */       t = t.getCause();
/*     */     } 
/* 101 */     s.append(getBlock(sw.toString()));
/* 102 */     getErrorLog().error(s.toString());
/*     */   }
/*     */   
/*     */   public static String getBlock(Object msg) {
/* 108 */     if (msg == null)
/* 110 */       msg = ""; 
/* 112 */     return "[" + msg.toString() + "]";
/*     */   }
/*     */   
/*     */   protected static String getParams(HttpServletRequest request) throws Exception {
/* 117 */     Map<String, String[]> params = request.getParameterMap();
/* 118 */     return JSON.marshal(params);
/*     */   }
/*     */   
/*     */   protected static String getUsername() {
/* 123 */     return (String)SecurityUtils.getSubject().getPrincipal();
/*     */   }
/*     */   
/*     */   public static Logger getAccessLog() {
/* 128 */     return ACCESS_LOG;
/*     */   }
/*     */   
/*     */   public static Logger getErrorLog() {
/* 133 */     return ERROR_LOG;
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\LogUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */